using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class SubstitutionStatusAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public SubstitutionStatusAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v231] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v24] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v25] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v251] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v26] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v27] = HL7TableType.HL7;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{"G","N","T"};
						validVersionCodes[HL7Version.v231] = new string[]{"N","G","T","0","1","2","3","4","5","7","8"};
						validVersionCodes[HL7Version.v24] = new string[]{"N","G","T","0","1","2","3","4","5","7","8"};
						validVersionCodes[HL7Version.v25] = new string[]{"N","G","T","0","1","2","3","4","5","7","8"};
						validVersionCodes[HL7Version.v251] = new string[]{"N","G","T","0","1","2","3","4","5","7","8"};
						validVersionCodes[HL7Version.v26] = new string[]{"N","G","T","0","1","2","3","4","5","7","8"};
						validVersionCodes[HL7Version.v27] = new string[]{"N","G","T","0","1","2","3","4","5","7","8"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{"A generic substitution was dispensed","No substitute was dispensed.  This is equivalent to the default (null) value.","A therapeutic substitution was dispensed"};
						validVersionDescriptions[HL7Version.v231] = new string[]{"No substitute was dispensed.  This is equivalent to the default (null) value.","A generic substitution was dispensed.","A therapeutic substitution was dispensed.","No product selection indicated","Substitution not allowed by prescriber","Substitution allowed - patient requested product dispensed","Substitution allowed - pharmacist selected product dispensed","Substitution allowed - generic drug not in stock","Substitution allowed - brand drug dispensed as a generic","Substitution not allowed - brand drug mandated by law","Substitution allowed - generic drug not available in marketplace"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"No substitute was dispensed.  This is equivalent to the default (null) value.","A generic substitution was dispensed.","A therapeutic substitution was dispensed.","No product selection indicated","Substitution not allowed by prescriber","Substitution allowed - patient requested product dispensed","Substitution allowed - pharmacist selected product dispensed","Substitution allowed - generic drug not in stock","Substitution allowed - brand drug dispensed as a generic","Substitution not allowed - brand drug mandated by law","Substitution allowed - generic drug not available in marketplace"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"No substitute was dispensed.  This is equivalent to the default (null) value.","A generic substitution was dispensed.","A therapeutic substitution was dispensed.","No product selection indicated","Substitution not allowed by prescriber","Substitution allowed - patient requested product dispensed","Substitution allowed - pharmacist selected product dispensed","Substitution allowed - generic drug not in stock","Substitution allowed - brand drug dispensed as a generic","Substitution not allowed - brand drug mandated by law","Substitution allowed - generic drug not available in marketplace"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"No substitute was dispensed.  This is equivalent to the default (null) value.","A generic substitution was dispensed.","A therapeutic substitution was dispensed.","No product selection indicated","Substitution not allowed by prescriber","Substitution allowed - patient requested product dispensed","Substitution allowed - pharmacist selected product dispensed","Substitution allowed - generic drug not in stock","Substitution allowed - brand drug dispensed as a generic","Substitution not allowed - brand drug mandated by law","Substitution allowed - generic drug not available in marketplace"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"No substitute was dispensed.  This is equivalent to the default (null) value.","A generic substitution was dispensed.","A therapeutic substitution was dispensed.","No product selection indicated","Substitution not allowed by prescriber","Substitution allowed - patient requested product dispensed","Substitution allowed - pharmacist selected product dispensed","Substitution allowed - generic drug not in stock","Substitution allowed - brand drug dispensed as a generic","Substitution not allowed - brand drug mandated by law","Substitution allowed - generic drug not available in marketplace"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"No substitute was dispensed.  This is equivalent to the default (null) value.","A generic substitution was dispensed.","A therapeutic substitution was dispensed.","No product selection indicated","Substitution not allowed by prescriber","Substitution allowed - patient requested product dispensed","Substitution allowed - pharmacist selected product dispensed","Substitution allowed - generic drug not in stock","Substitution allowed - brand drug dispensed as a generic","Substitution not allowed - brand drug mandated by law","Substitution allowed - generic drug not available in marketplace"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
